//
//  ViewController.m
//  testmap
//
//  Created by bilinguis on 13-7-15.
//  Copyright (c) 2013年 __MyCompanyName__. All rights reserved.
//

#import "RCMapViewController.h"
#import <MapKit/MapKit.h>
#import "RCPointAnnotation.h"
#define METERS_PER_MILE 1609.344


@implementation RCMapViewController{
    CLLocationCoordinate2D coor;
    NSString               *_pointTitle;
}

@synthesize pointTitle = _pointTitle;
@synthesize mapView = _mapView;


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle



- (id) initWithCoor:(CLLocationCoordinate2D)coordinate andName:(NSString *)title
{
    self = [super init];
    if (self) {
        coor = coordinate;
        self.pointTitle = title;
    }
    
    return self;
}


- (void) dealloc
{
    self.pointTitle = nil;
    self.mapView = nil;
    
    [super dealloc];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    _mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, UIScreenHeight)];
    [self.viewContainer addSubview:_mapView];
    [_mapView setShowsUserLocation:YES];

    _mapView.delegate = self;
    
    
    MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(coor, 0.5*METERS_PER_MILE, 0.5*METERS_PER_MILE);
    [_mapView setRegion:viewRegion animated:YES];
    
    
  
    RCPointAnnotation *annotation = [[RCPointAnnotation alloc] initWithName:self.pointTitle address:nil coordinate:coor];
    [_mapView addAnnotation:annotation];
    [annotation release];
    
    self.titleLabelText = @"商户地图";
    self.navigationItem.titleView = [self createTitleView];
    
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}




@end
